package com.itheima.个人代码.IO流2;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class Demo17 {
    public static void main(String[] args) throws IOException {
        propload();
        //propStore();
        propLogin();

    }

    private static void propLogin() throws IOException {
        Scanner sc = new Scanner(System.in);
        Properties prop = new Properties();
        FileReader fr = new FileReader("IO流2和对象操作流properties\\prop.properties");
        prop.load(fr);
        System.out.println("请输入用户名: ");
        String username = sc.next();
        System.out.println("请输入密码名: ");
        String password = sc.next();
        String pass = prop.getProperty(username);
        if(pass!=null&&password.equals(pass)){
            System.out.println("恭喜您,登录成功....");
        }else{
            System.out.println("用户名或密码不正确........");
        }
        fr.close();
    }

    private static void propStore() throws IOException {
        FileWriter fw = new FileWriter("IO流2和对象操作流properties\\prop.properties");
        Properties prop = new Properties();
        prop.setProperty("zhangsan", "333");
        prop.setProperty("lisi", "444");
        prop.setProperty("wangwu", "555");
        prop.setProperty("maliu", "666");
        prop.setProperty("suqi", "777");
        prop.setProperty("wangba", "888");
        prop.setProperty("lijiu", "999");
        prop.store(fw, "暂时没有注释..........");
        fw.close();

    }

    public static void propload() throws IOException {
        Properties prop = new Properties();
        FileReader fr = new FileReader("IO流2和对象操作流properties\\prop.properties");
        prop.load(fr);
        System.out.println(prop);
        fr.close();
    }
}
